
from selenium.webdriver.common.by import By
from webapp1.po.login_page import LogninPage
from webapp1.po.base_page import BasePage
from webapp1.po.register_page import RegisterPage


class NavBar(BasePage):
    _index_link = By.CSS_SELECTOR, 'ul[class="nav pull-right"] a[href="/"]'
    _unread_link = By.CSS_SELECTOR, 'ul[class="nav pull-right"] a[href="/my/messages"]'
    _newman_link = By.CSS_SELECTOR, 'ul[class="nav pull-right"] a[href="/getstart"]'
    _api_link = By.CSS_SELECTOR, 'ul[class="nav pull-right"] a[href="/api"]'
    _about_link = By.CSS_SELECTOR, 'ul[class="nav pull-right"] a[href="/about"]'
    _set_link = By.CSS_SELECTOR, 'ul[class="nav pull-right"] a[href="/setting"]'
    _quit_link = By.CSS_SELECTOR, 'ul[class="nav pull-right"] a[href="/signout"]'
    _login_link = By.CSS_SELECTOR, 'ul[class="nav pull-right"] a[href="/signin"]'
    _register_link = By.CSS_SELECTOR, 'ul[class="nav pull-right"] a[href="/signup"]'
    _user_name_link = By.CSS_SELECTOR,'span.user_name >a.dark'

    # 首页界面
    def go_to_index_page(self):
        print(self._index_link)
        self._driver.find_element(*self._index_link).click()

    # 未读界面
    def go_to_unread_page(self):
        print(self._unread_link)
        self._driver.find_element(*self._unread_link).click()

    # 新手入门界面
    def go_to_newman_page(self):
        print(self._newman_link)
        self._driver.find_element(*self._newman_link).click()
        print(*self._newman_link)

    # API界面
    def go_to_api_page(self):
        print(self._api_link)
        self._driver.find_element(*self._api_link).click()

    # 关于界面
    def go_to_about_page(self):
        print(self._about_link)
        self._driver.find_element(*self._about_link).click()

    # 设置界面
    def go_to_set_page(self):
        print(self._set_link)
        self._driver.find_element(*self._set_link).click()

    # 退出界面
    def go_to_quit_page(self):
        print(self._quit_link)
        self._driver.find_element(*self._quit_link).click()

    # 登陆界面
    def go_to_login_page(self) :
        # print(self._login_link)
        self._driver.find_element(*self._login_link).click()
        return LogninPage(self._driver)

    # 注册界面
    def go_to_register_page(self):
        self._driver.find_element(*self._register_link).click()
        # print(self._register_link)
        return RegisterPage(self._driver)

    # 用户中心界面
    def go_to_user_conter_page(self):
        self._driver.find_element(*self._user_name_link)

    # 用户信息
    @property
    def user_name_text(self):
        return self._driver.find_element(*self._user_name_link).text


# if __name__ == '__main__':
#     driver = webdriver.Chrome()
#     driver.implicitly_wait(10)
#     driver.get('http://47.100.175.62:3000/')
#     navbar = NavBar(driver)
#     # navbar.go_to_newman_page()
#     # navbar.go_to_register_page()
